<template>
  <div class="home-container">
    <el-container class="home_container">
      <el-header>
        <div class="logo">
          <img src="../../assets/three.png" />
          <span>YSJ后台管理系统</span>
        </div>
        <el-button type="info" @click="loginout">退出</el-button>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '64px' : '200px'">
          <div class="toggleMenu" @click="isCollapse=!isCollapse">$</div>
          <el-menu
            background-color="#333744"
            text-color="#fff"
            :unique-opened="true"
            :collapse="isCollapse"
            :collapse-transition="false"
            router
            :default-active="$route.path"
            active-text-color="blue">
            <el-submenu v-for="item in menuList" :key="item.id" :index="item.id + ''">
              <!-- 一级标题 -->
              <template slot="title">
                <i :class="iconsList[item.id]"></i>
                <span>{{ item.authName }}</span>
              </template>
              <!-- 二级标题 -->
              <el-menu-item v-for="item2 in item.children" :key="item2.id" :index="'/' + item2.path" >
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{ item2.authName }}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <!-- 路由占位 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: 'Home',
  data () {
    return {
      menuList: [],
      iconsList: {
        125: 'iconfont icon-users',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao'
      },
      isCollapse: false
    }
  },

  created () {
    this.getMenuList()
  },

  methods: {
    loginout () {
      sessionStorage.removeItem('token')
      this.$router.push('/login')
    },
    // 获取菜单数据
    async getMenuList () {
      const { data: res } = await this.$axios.get('menus')
      // console.log(res)
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.menuList = res.data
    }
  }
}
</script>

<style scoped lang='less'>
.home-container {
  height: 100%;
  .home_container{
  height:100%;
}
  .el-header {
  background: #373d41;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .logo {
    display: flex;
    align-items: center;
    img {
      width: 50px;
      height: 50px;
    }
    span {
      margin-left: 15px;
      color: silver;
      font-size: 40px;
      font-weight: bold;
      }
    }
  }
  .el-aside {
  background: #373d41;
  .iconfont {
    margin-right: 10px;
  }
  .el-menu {
    border-right: none;
  }
  .toggleMenu {
    width: 100%;
    height: 30px;
    line-height: 30px;
    text-align: center;
    color: #fff;
    font-weight: bold;
    font-size: 40px;
    background: blue;
    letter-spacing: 8px;
    cursor: pointer;
    user-select: none;
  }
}
  .el-main {
  background: #ccc;
  }
}
</style>
